<?php
$smarty->configLoad($lang . '/petitions.module.php');
$language = parse_ini_file($lang . '/breadcrumb.module.php', true);
$_language = parse_ini_file($lang . '/petitions.module.php', true);
$breadcrumb = $language['petitions_replay'];
$char = new character;
$user = new user;
$sql = 'SELECT * FROM '.DB_GAME.'.petitions WHERE id = :id';
$dbh = $connection->prepare($sql);
$dbh->bindValue(':id', $_GET['id']); 
$dbh->execute();
foreach($dbh->fetchAll(PDO::FETCH_ASSOC) as $row) {
	$row['accountname'] = $user->getName($char->getAccountID($row['playerId']));
	if($row['status'] == 'PENDING') {
		$row['status'] = $_language['PENDING'];
	} elseif($row['status'] == 'REPLIED') {
		$row['status'] = $_language['REPLIED'];
	} elseif($row['status'] == 'IN_PROGRESS') {
		$row['status'] = $_language['IN_PROGRESS'];
	}
	$value[] = $row;
}
if(isset($_POST['replay'])) {
	$user->sendIngameMail($_POST['title'], $_POST['uid'], $_POST['message']);
	
	$sql = 'UPDATE ' . DB_GAME . '.petitions SET status = "REPLIED"  WHERE id = :id';
	$dbh = $connection->prepare($sql);
	$dbh->bindValue(':id', $_GET['id']);
	$dbh->execute();
	$main->jqmodal('replayed');
	echo '<meta http-equiv="refresh" content="5; URL=index.php?mod=petitions">';

}
$smarty->assign('value', $value);
$template = 'petitions/replay.tpl';
?>
